{%TEMPLATE->struct/head%}
{%TEMPLATE->struct/menu%}
<h2>Preconfigured tasks ([[sizeof([[tasks]])]])</h2>
{%TEMPLATE->struct/messages%}
<div class="card">
  <div class="table-responsive">
    <table class="table table-bordered table-sm" id="pretasks">
      <thead>
        <tr>
          <th>ID</th>
          <th>Name</th>
          <th>Attack command</th>
          <th>Files</th>
          <th>Priority</th>
          <th>Max agents</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
		    {{FOREACH task;[[tasks]]}}
			    <tr>
				    <td{{IF [[strlen([[task.getVal('Task').getColor()]])]] > 0}} style="background-color: #[[task.getVal('Task').getColor()]]"{{ENDIF}}>
					    <a href="pretasks.php?id=[[task.getVal('Task').getId()]]">[[task.getVal('Task').getId()]]</a>
				    </td>
				    <td>
					    <a href="pretasks.php?id=[[task.getVal('Task').getId()]]">[[task.getVal('Task').getTaskName()]]</a>
				    </td>
            <td>[[task.getVal('Task').getAttackCmd()]]</td>
            <td data-sort="[[task.getVal('filesSize')]]">
              {{IF [[task.getVal('numFiles')]] > 0}}
                [[task.getVal('numFiles')]] ([[Util::nicenum([[task.getVal('filesSize')]])]]B)
              {{ENDIF}}
              {{IF [[task.getVal('fileSecret')]] == 1}}
                <span class="fas fa-lock" aria-hidden="true"></span>
              {{ENDIF}}
            </td>
            <td data-sort="[[task.getVal('Task').getPriority()]]">
					    {{IF [[accessControl.hasPermission([[$DAccessControl::MANAGE_PRETASK_ACCESS]])]]}}
						    <form class='form-inline' action="pretasks.php" method="POST">
							    <input type="hidden" name="action" value="[[$DPretaskAction::SET_PRIORITY]]">
							    <input type="hidden" name="pretaskId" value="[[task.getVal('Task').getId()]]">
							    <input type="hidden" name="csrf" value="[[csrf]]">
							    <input type="text" class='form-control' name="priority" size="4" value="[[task.getVal('Task').getPriority()]]" title="Priority">
							    <button type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} mx-1' data-toggle="tooltip" data-placement="top" title="Set"><i class="fas fa-save" aria-hidden="true"></i></button>
						    </form>
					    {{ELSE}}
						    [[task.getVal('Task').getPriority()]]
					    {{ENDIF}}
            </td>
            <td data-sort="[[task.getVal('Task').getMaxAgents()]]">
                {{IF [[accessControl.hasPermission([[$DAccessControl::MANAGE_PRETASK_ACCESS]])]]}}
                <form class='form-inline' action="pretasks.php" method="POST">
                    <input type="hidden" name="action" value="[[$DPretaskAction::SET_MAX_AGENTS]]">
                    <input type="hidden" name="pretaskId" value="[[task.getVal('Task').getId()]]">
                    <input type="hidden" name="csrf" value="[[csrf]]">
                    <input type="text" class='form-control' name="maxAgents" size="4" value="[[task.getVal('Task').getMaxAgents()]]" title="Max agents">
                    <button type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} mx-1' data-toggle="tooltip" data-placement="top" title="Set"><i class="fas fa-save" aria-hidden="true"></i></button>
                </form>
                {{ELSE}}
                  [[task.getVal('Task').getMaxAgents()]]
                {{ENDIF}}
            </td>
            <td>
					    {{IF [[accessControl.hasPermission([[$DAccessControl::CREATE_PRETASK_ACCESS]])]]}}
						    <form class="float-right mx-1" action="pretasks.php" method="POST" onSubmit="if (!confirm('Really delete task [[task.getVal('Task').getId()]]?') || ({{IF [[task.getVal('isUsed')]]}}true{{ELSE}}false{{ENDIF}} && !confirm('This task is used in a Supertask, are you sure you really want to delete it?'))) return false;">
							    <input type="hidden" name="action" value="[[$DPretaskAction::DELETE_PRETASK]]">
							    <input type='hidden' name='refer' value='pretask'>
							    <input type="hidden" name="pretaskId" value="[[task.getVal('Task').getId()]]">
							    <input type="hidden" name="csrf" value="[[csrf]]">
                  <button type="submit" class='btn btn-danger' data-toggle="tooltip" data-placement="top" title="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button>
						    </form>
					    {{ENDIF}}
					    {{IF [[accessControl.hasPermission([[$DAccessControl::RUN_TASK_ACCESS]])]]}}
						    <form class="float-right mx-1" action="tasks.php?new=true&copyPre=[[task.getVal('Task').getId()]]" method="POST">
                  <button type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' data-toggle="tooltip" data-placement="top" title="Copy to Task"><i class="fas fa-copy" aria-hidden="true"></i></button>
						    </form>
					    {{ENDIF}}
              {{IF [[accessControl.hasPermission([[$DAccessControl::CREATE_PRETASK_ACCESS]])]]}}
						    <form class="float-right mx-1" action="pretasks.php?new=true&copy=[[task.getVal('Task').getId()]]" method="POST">
                  <button type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}' data-toggle="tooltip" data-placement="top" title="Copy to Pretask"><i class="fas fa-bookmark" aria-hidden="true"></i></button>
						    </form>
					    {{ENDIF}}
				    </td>
			    </tr>
		    {{ENDFOREACH}}
      </tbody>
	  </table>
    <script type="text/javascript">
      $(document).ready(function () {
        $('#pretasks').DataTable({
          pageLength: 50,
          "order": [ [0, 'asc'] ],
          "columnDefs": [
            { "orderable": false, "targets": [2, 5] },
            { "orderable": true, "targets": [0, 1, 3, 4] }
          ]
        });
      });
    </script>
  </div>
</div>
{%TEMPLATE->struct/foot%}
